package test.administrator.example.com.mvptest1.demo.lce;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import test.administrator.example.com.mvptest1.R;

public class CountriesAdapter extends RecyclerView.Adapter<CountriesAdapter.ViewHolder> {

	private List<Country> countries;


	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}

	public List<Country> getCountries() {
		return countries;
	}

	@Override
	public int getItemCount() {
		return countries == null ? 0 : countries.size();
	}

	@Override
	public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View v = LayoutInflater.from(parent.getContext())
				.inflate(R.layout.row_text, parent, false);
		ViewHolder viewHolder = new ViewHolder(v);
		return viewHolder;
	}

	@Override
	public void onBindViewHolder(ViewHolder holder, int position) {
		// 绑定数据
		holder.name.setText(countries.get(position).getName());
	}

	public static class ViewHolder extends RecyclerView.ViewHolder {

		TextView name;

		public ViewHolder(View itemView) {
			super(itemView);
			name = itemView.findViewById(R.id.textView);
		}
	}

}


